package com.lzy.algorithm;

public class 最大子序列和 {

    public static void main(String[] args) {
        int[] nums = new int[]{3, -1, 6, 7, -5, -6, 0, 3, 2};
        int anc = nums[0];
        int sum = 0;

        for (int i = 0; i < nums.length; i++) {
            int num = nums[i];
            if (sum < 0) {
                sum = num;
            } else {
                sum = sum + num;
            }
            anc = Math.max(anc, sum);
        }

        System.out.println(anc);
    }
}
